/*
 *  Copyright 2011 yura.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package org.opu.vcforms.template;

import java.util.Iterator;
import java.util.List;
import org.simpleframework.xml.ElementList;
import org.simpleframework.xml.Root;

/**
 *
 * @author yura
 */
@Root(name="document")
public class Document implements Iterable<Data> {

    @ElementList(inline = true, required = false, type = Data.class)
    private List<Data> dataList;

    public List<Data> getDataList() {
        return dataList;
    }

    public void setDataList(List<Data> dataList) {
        this.dataList = dataList;
    }

    public int size() {
        if (dataList != null) {
            return dataList.size();
        } else {
            return 0;
        }
    }

    @Override
    public Iterator<Data> iterator() {
        if (dataList != null) {
            return dataList.iterator();
        } else {
            return new Iterator<Data>() {

                @Override
                public boolean hasNext() {
                    return false;
                }

                @Override
                public Data next() {
                    return null;
                }

                @Override
                public void remove() {
                }
            };
        }
    }

    public boolean isEmpty() {
        if (dataList != null) {
            return dataList.isEmpty();
        } else {
            return true;
        }
    }

    public Data get(int i) {
        if (dataList != null) {
            return dataList.get(i);
        } else {
            return null;
        }
    }
}
